﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Public;


namespace WebsiteAdmin.Suunto
{
    public partial class Dashboard : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            GetDBData();

        }

        protected void GetDBData()
        {
            DataTable dtRtn = new DataTable();
            // Add three column objects to the table.
            DataColumn dc1 = new DataColumn();
            dc1.DataType = System.Type.GetType("System.String");
            dc1.ColumnName = "name";
            //dc1.AutoIncrement = true;
            dtRtn.Columns.Add(dc1);

            DataColumn dc2 = new DataColumn();
            dc2.DataType = System.Type.GetType("System.Int32");
            dc2.ColumnName = "fileid";
            //dc2.AutoIncrement = true;
            dtRtn.Columns.Add(dc2);



            DataColumn dc3 = new DataColumn();
            dc3.DataType = System.Type.GetType("System.String");
            dc3.ColumnName = "filegroup";
            //dc3.AutoIncrement = true;
            dtRtn.Columns.Add(dc3);

            DataColumn dc4 = new DataColumn();
            dc4.DataType = System.Type.GetType("System.String");
            dc4.ColumnName = "size";
            //dc4.AutoIncrement = true;
            dtRtn.Columns.Add(dc4);

            DataColumn dc5 = new DataColumn();
            dc5.DataType = System.Type.GetType("System.String");
            dc5.ColumnName = "maxsize";
            //dc5.AutoIncrement = true;
            dtRtn.Columns.Add(dc5);

            DataColumn dc6 = new DataColumn();
            dc6.DataType = System.Type.GetType("System.String");
            dc6.ColumnName = "growth";
            //dc5.AutoIncrement = true;
            dtRtn.Columns.Add(dc6);


            DataColumn dc7 = new DataColumn();
            dc7.DataType = System.Type.GetType("System.String");
            dc7.ColumnName = "usage";
            //dc2.AutoIncrement = true;
            dtRtn.Columns.Add(dc7);

            DataColumn dc8 = new DataColumn();
            dc8.DataType = System.Type.GetType("System.String");
            dc8.ColumnName = "filename";
            //dc2.AutoIncrement = true;
            dtRtn.Columns.Add(dc8);


            DataTable dt = new DataTable();
            dt = Bll.Setting.GETDBSIZE(Global.ConnSuunto);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dtRtn.NewRow();
                dr["name"] = dt.Rows[i]["name"].ToString();
                dr["fileid"] = Convert.ToInt32(dt.Rows[i]["fileid"]);
                dr["filegroup"] = dt.Rows[i]["filegroup"].ToString();
                dr["size"] = (Convert.ToInt64(dt.Rows[i]["size"].ToString().Replace(" KB", "")) / 1024).ToString() + " MB";

                if (dt.Rows[i]["maxsize"].ToString() == "Unlimited" || dt.Rows[i]["maxsize"].ToString() == "2147483648 KB")
                    dr["maxsize"] = "Unlimited";
                else
                    dr["maxsize"] = (Convert.ToInt64(dt.Rows[i]["maxsize"].ToString().Replace(" KB", "")) / 1024).ToString() + " MB";
                //dr["maxsize"] = dt.Rows[i]["maxsize"].ToString();
                dr["growth"] = dt.Rows[i]["growth"].ToString();
                dr["usage"] = dt.Rows[i]["usage"].ToString();
                dr["filename"] = dt.Rows[i]["filename"].ToString();
                dtRtn.Rows.Add(dr);

            }
            dt.Dispose();

            if (dtRtn.Rows.Count > 0)
            {
                RP_Db.DataSource = dtRtn.DefaultView;
                RP_Db.DataBind();
            }

            dtRtn.Dispose();


        }

        protected void DeleteLog_Click(object sender, EventArgs e)
        {
            int rtn = Bll.Setting.DeleteLog(Global.ConnSuunto);
            Response.Redirect("Dashboard.aspx");
        }


    }
}
